<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head> 
   <meta charset="UTF-8">
   <%@ include file="/WEB-INF/views/include/head.jsp"%>
   <link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
   <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
   <c:set value="<%=ResourcesUtil.getConfig(\"clothes_in_category_processing\")%>" var="varClothesInProcessing" />
   <c:set value="<%=ResourcesUtil.getConfig(\"clothes_in_category_production\")%>" var="varClothesInProduction" />   
   <script src="${ctxStatic}/js/jquery-1.9.1.min.js"></script>
   <script src="${ctxStatic}/js/layer.js"></script>
   <script src="${ctxStatic}/js/style.js"></script>
   <script src="${ctxStatic}/jquery-barcode/jquery-barcode.js" type="text/javascript"></script>
   <script type="text/javascript">
   // 外发生产入库
   var clothesInProcessing = "${varClothesInProcessing}";
   // 生产成衣入库
   var clothesInProduction = "${varClothesInProduction}";
   
	$(document).ready(function(){
		$("#inventoryCategory").select2();
		$("#productionId").select2();
		$("#fabricatId").select2();
		$("#contractProcessId").select2();
		$("#styleId").select2();
		
		selectListControl();
		
		//$("#inventoryRequestBarCodeDiv").empty().barcode($("#stockBarCode").val(), "code128",{barWidth:2, barHeight:30,showHRI:false});
	});
	
	// 下拉列表制御
	function selectListControl(){
		var vInCatagory = $("#inventoryCategory").val();
		if(vInCatagory == clothesInProduction){
            $('#styleShow').show();
            $('#clothesInProductionShow').show();
            $('#clothesInProcessingShow').hide();
		}else if(vInCatagory == clothesInProcessing){
            $('#styleShow').show();
            $('#clothesInProductionShow').hide();
            $('#clothesInProcessingShow').show();
		}else{
			$('#styleShow').hide();
            $('#clothesInProductionShow').hide();
            $('#clothesInProcessingShow').hide();
		}
	}
	
	// 根据入库类别制御下拉列表
	function selInventoryCategory(){
		
		// 清空下拉生产制单号
		$("#productionId").val('');
		$("#productionId").select2();
		// 清空下拉加工厂
		$("#fabricatId").val('');
		$("#fabricatId").select2();
		
		var html="<option value=''><spring:message code="customer_pleaseChoose"/></option>";
		// 清空下拉外发合同
		$("#contractProcessId").html(html);
		$("#contractProcessId").select2();
		// 清空下拉款号
		$("#styleId").html(html);
		$("#styleId").select2();
		// 清空客户订单号
		$("#customerContractNo").val('');
		// 清空入库申请单号
		$("#inventoryRequestNo").val('');
		// 清空合同单id
		$("#contractId").val('');
		// 清空合同订单id
		$("#indentId").val('');
		
		// 清空明细
		delAllDetails();
		
		selectListControl();
	}
	
    function delAllDetails(){
        // 调用后台更新数据
        $.post("${ctx}/slopwork/inrequest/delAllDetails",'',function(result) {
            // 回调函数赋值
            var h = $(callBackHtml(result)).find("#tableRequestDetails").html();
            $('#tableRequestDetails').html(h);
        }, 'html');
    }

	// 生产制单联动
	function productSelFun(){		
			// 生产制单联动
			var paramPorductionId = $("#productionId").val();
			var param={"productionId":paramPorductionId};
	        $.post("${ctx}/slopwork/inrequest/selProduction",param,function(result){            
	        	// 回调函数赋值
	            var hNo = $(callBackHtml(result)).find("#divInventoryRequestNo").html();
	            $('#divInventoryRequestNo').html(hNo);
	        
 		        var hCustomerNo = $(callBackHtml(result)).find("#divCustomerContractNo").html();
		        $('#divCustomerContractNo').html(hCustomerNo);
	    
			    var hStyle = $(callBackHtml(result)).find("#divStyleId").html();
			    $('#divStyleId').html(hStyle);
			    $('#styleId').select2();
			    $('#styleId').attr('disabled',true);

				var hDetails = $(callBackHtml(result)).find("#tableRequestDetails").html();
				$('#tableRequestDetails').html(hDetails);
				}, 'html');
	}
	
	// 加工厂单联动
	function fabricatSelFun(){		
			// 生产制单联动
			var paramFabricatId = $("#fabricatId").val();
			var param={"fabricatId":paramFabricatId};
	        $.post("${ctx}/slopwork/inrequest/selFabricat",param,function(result){            
			    var h = $(callBackHtml(result)).find("#divContractProcessId").html();
			    $('#divContractProcessId').html(h);
			    $('#contractProcessId').select2();
			    
			    var html="<option value=''><spring:message code="customer_pleaseChoose"/></option>";
				// 清空下拉款号
				$("#styleId").html(html);
				$("#styleId").select2();
				// 清空客户订单号
				$("#customerContractNo").val('');
				// 清空入库申请单号
				$("#inventoryRequestNo").val('');
				// 清空合同单id
				$("#contractId").val('');
				// 清空合同订单id
				$("#indentId").val('');
				
				// 清空明细
				delAllDetails();
				
	        }, 'html');
	}
	
	// 外发合同联动
	function contractProcessSelFun(){		
		// 生产制单联动
		var paramContractProcessId = $("#contractProcessId").val();
		var param={"contractProcessId":paramContractProcessId};
        $.post("${ctx}/slopwork/inrequest/selContractProcess",param,function(result){            
		    var hStyle = $(callBackHtml(result)).find("#divStyleId").html();
		    $('#divStyleId').html(hStyle);
		    $('#styleId').select2();
		    
			// 清空客户订单号
			$("#customerContractNo").val('');
			// 清空入库申请单号
			$("#inventoryRequestNo").val('');
			// 清空合同单id
			$("#contractId").val('');
			// 清空合同订单id
			$("#indentId").val('');
			
			// 清空明细
			delAllDetails();
			}, 'html');
	}
	
	// 款式联动
	function styleSelFun(){		
		// 生产制单联动
		var paramStyleId = $("#styleId").val();
		var paramContractId = $("#contractProcessId").val();
		var param={"styleId":paramStyleId,"contractProcessId":paramContractId};
        $.post("${ctx}/slopwork/inrequest/selStyle",param,function(result){            
        	// 回调函数赋值
            var hNo = $(callBackHtml(result)).find("#divInventoryRequestNo").html();
            $('#divInventoryRequestNo').html(hNo);
        
		    var hCustomerNo = $(callBackHtml(result)).find("#divCustomerContractNo").html();
	        $('#divCustomerContractNo').html(hCustomerNo);
	        
			var hDetails = $(callBackHtml(result)).find("#tableRequestDetails").html();
			$('#tableRequestDetails').html(hDetails);
			
			}, 'html');
	}
	//获取 iframe 数量 
	var frLength = window.parent.frames.length;
	//父画面下标 
	var parentIndex = frLength-2;
    //保存方法
    var saveForm={
         t:null,
         save:function(t){
        	 
         	 if($("#tableRequestDetails tr").length==0){
        		 layer.msg('<spring:message code="slopworkInRequest_create_msg_details"/>', {time:1000});
        		 return;
        	 } 
        	 
              $(t).attr("disabled",true);
              this.t=t;
              // 表单验证
              $("#inputForm").validate({
              fail: function(element,e) {  
                  $(saveForm.t).attr("disabled",false);
              },
                   submitHandler: function() {
                	   $('#styleId').attr('disabled',false);
                       $('#inventoryCategory').attr('disabled',false);
                   	   // 格式化，去除逗号
                       formUnFormat($("#inputForm"));
                        // 从表单获取数据信息
                        var params = $("#inputForm").serialize();
                        // 调用后台保存方法
                        $.post("${ctx}/slopwork/inrequest/save",params,function(result){
                             // 提示信息
                             tipParent(result.message);
                             // 返回状态
                             if(result.statusCode==STATUSCODEOK){
                                 // 刷新页面
                                 window.parent.frames[0].searchListForm();
                                 if("${slopworkInRequest.statusFlg ne null }" ){
                                     window.parent.frames[parentIndex].closeWin();
                                 }
                                 closeWin();
                             }else{
                                  $(saveForm.t).attr("disabled",false);
                             }
                        },'json'); 
                   }
              });
              // 提交表单
              $("#inputForm").submit(); 
         } 
    }
    
    function funFormatNumber(obj){
    	
    	var intReg = /^[0-9]+$/;   
    	var floatReg = /^[0-9]+.?[0-9]*$/;   
    	var s = $(obj).val();
        
    	// 整数
    	if(intReg.test(s)){
    		var numberTen = /^[0-9]{1,7}$/;
			if (!numberTen.test(s)){
				$(obj).val('');
			}
		// 小数	
    	}else if(floatReg.test(s)){
    		var numberVerification = /^[0-9]{1,7}.?[0-9]{0,3}$/;  
			if (!numberVerification.test(s)){
				$(obj).val('');
			}
    	}else{
    		$(obj).val('');
    	}
    	formatNumber(obj);
    }
	</script>
</head>
<body>
<div class="layerHeader clearfix">
	<p class="headerTitle"><spring:message code="slopworkInRequest_create_head" /></p>
    <div class="headerButton clearfix">
        <!-- 保存 -->
        <button type="button" onclick="saveForm.save(this)"><spring:message code="common_save"/></button>
        <!-- 取消 -->
        <button onclick="closeWin()"><spring:message code="btn_cancle"/></button>
    </div>
</div>
<form id="inputForm" method="post">
<c:set value="<%=ResourcesUtil.getConfig(\"clothes_in_category\")%>" var="varInventoryCategory" />
<input type="hidden" id="id" name="id" value="${slopworkInRequest.id}"/>
    <!-- 入库单条码 -->
<input type="hidden" id="stockBarCode" name="stockBarCode" value="${slopworkInRequest.stockBarCode}">
<div class="smOrderBox">
    <div class="items clearfix">
        <div class="col-33 clearfix" id="divInventoryRequestNo">
            <!-- 入库单号 -->
            <p class="tit"><spring:message code="slopworkInRequest_show_inventoryRequestNo" /></p>
            <input style="background-color:inherit;color:#333;" type="text" id="inventoryRequestNo" name="inventoryRequestNo" value="${slopworkInRequest.inventoryRequestNo}" readonly="true">
            <input type="hidden" id="contractId" name="contractId" value="${slopworkInRequest.contractId}"/>
            <input type="hidden" id="indentId" name="indentId" value="${slopworkInRequest.indentId}"/>
            <input type="hidden" id="styleIdold" name="styleIdold" value="${slopworkInRequest.styleId}"/>
            <input type="hidden" id="statusFlg" name="statusFlg" value="${slopworkInRequest.statusFlg}"/>
            <!--样品需求单Id -->
            <input type="hidden" id="sampleRequestId" name="sampleRequestId" value="${slopworkInRequest.sampleRequestId}"/>
        </div>
        <div class="col-33 clearfix">
            <!-- 入库类别 -->
            <c:set value="<%=ResourcesUtil.getConfig(\"clothes_in_category_Samply\")%>" var="varClothesInSamply" />
            <p class="tit"><spring:message code="slopworkInRequest_show_inventoryCategory" /></p>
            <c:choose>
                <c:when test="${slopworkInRequest.inventoryCategory ne  varClothesInSamply}">
                    <select style="width:52%" id="inventoryCategory" name="inventoryCategory" onchange="selInventoryCategory();">
                <option value=""><spring:message code="customer_pleaseChoose"/></option>
                <c:forEach items="${fns:getDictList(varInventoryCategory)}"   var="inventoryCategoryInfo">
                    <c:if test="${inventoryCategoryInfo.itemValue ne fn:split(varClothesInSamply,'-')[1] }">
                    <option <c:if test="${fn:split(slopworkInRequest.inventoryCategory,'-')[1] eq inventoryCategoryInfo.itemValue}">selected="selected"</c:if> value="${inventoryCategoryInfo.itemCode}-${inventoryCategoryInfo.itemValue}" >
                            ${inventoryCategoryInfo.itemName}
                    </option>
                    </c:if>
                </c:forEach>
            </select>
                </c:when>
                <c:when test="${slopworkInRequest.inventoryCategory eq varClothesInSamply}">
                    <select style="width:52%" id="inventoryCategory" name="inventoryCategory" disabled="disabled">
                    <c:forEach items="${fns:getDictList(varInventoryCategory)}"   var="inventoryCategoryInfo">
                        <c:if test="${inventoryCategoryInfo.itemValue eq fn:split(varClothesInSamply,'-')[1] }">
                            <option selected="selected" value="${inventoryCategoryInfo.itemCode}-${inventoryCategoryInfo.itemValue}" >
                                    ${inventoryCategoryInfo.itemName}
                            </option>
                        </c:if>
                    </c:forEach>
                </select>
                </c:when>
            </c:choose>
        </div>
    </div>
    <div class="items clearfix">
        <div id = "clothesInProductionShow">
            <div class="col-33 clearfix">
            <!-- 生产制单号 -->
            <p class="tit" style="width:75px;"><spring:message code="slopworkInRequest_show_production" /></p>
            <select style="width:52%" id="productionId" name="productionId" onchange="productSelFun();">
               <option value=""><spring:message code="customer_pleaseChoose"/></option>
               <c:forEach items="${slopworkInRequest.productionNoList}" var="productionNoInfo">
                  <option <c:if test="${slopworkInRequest.productionId eq productionNoInfo.productionId}">selected="selected"</c:if> value="${productionNoInfo.productionId}" > 
                     ${productionNoInfo.productionNo}
                  </option>
               </c:forEach>
            </select>
        </div>
            <div class="col-33 clearfix" id="divCustomerContractNo">
            <!-- 客户订单号 -->
            <p class="tit"><spring:message code="slopworkInRequest_show_customerContractNo" /></p>
            <input style="background-color:inherit;color:#333;" type="text" id="customerContractNo" name="customerContractNo" value="${slopworkInRequest.customerContractNo}" readonly="true" />
        </div>
        </div>
        <div id="clothesInProcessingShow">
            <div class="col-33 clearfix">
                <!-- 加工厂名称 -->
                <p class="tit"><spring:message code="slopworkInRequest_show_fabricatName" /></p>
                <select style="width:52%" id="fabricatId" name="fabricatId" onchange="fabricatSelFun();">
                    <option value=""><spring:message code="customer_pleaseChoose"/></option>
                    <c:forEach items="${slopworkInRequest.fabricatList}" var="fabricatInfo">
                        <option <c:if test="${slopworkInRequest.fabricatId eq fabricatInfo.ognizationID}">selected="selected"</c:if> value="${fabricatInfo.ognizationID}" >
                                ${fabricatInfo.ognizationName}
                        </option>
                    </c:forEach>
                </select>
            </div>
            <div class="col-33 clearfix" id="divContractProcessId">
                <!-- 外发合同订单  -->
                <p class="tit" style="width:75px;"><spring:message code="slopworkInRequest_show_process" /> </p>
                <select style="width:52%" id="contractProcessId" name="contractProcessId" onchange="contractProcessSelFun();">
                    <option value=""><spring:message code="customer_pleaseChoose"/></option>
                    <c:forEach items="${slopworkInRequest.contractProcessList}" var="contractProcessInfo">
                        <option <c:if test="${slopworkInRequest.contractProcessId eq contractProcessInfo.contractProcessId}">selected="selected"</c:if> value="${contractProcessInfo.contractProcessId}" >
                                ${contractProcessInfo.contractProcessNo}
                        </option>
                    </c:forEach>
                </select>
            </div>
        </div>
        <div id="styleShow">
            <div class="col-33 clearfix" id="divStyleId">
                <!-- 款式 -->
                <p class="tit"><spring:message code="slopworkInRequest_show_style" /></p>
                <select style="width:52%" id="styleId" name="styleId" onchange="styleSelFun();">
                    <option value=""><spring:message code="customer_pleaseChoose"/></option>
                    <c:forEach items="${slopworkInRequest.styleList}" var="styleInfo">
                        <option <c:if test="${slopworkInRequest.styleId eq styleInfo.styleId}">selected="selected"</c:if> value="${styleInfo.styleId}" >
                                ${styleInfo.customerStyleNo}
                        </option>
                    </c:forEach>
                </select>
            </div>
        </div>
    </div>
</div>
<div class="tableArea">
    <div class="tableScrollSm" style="overflow:auto;width:875px;height:420px;">
        <table cellpadding="0" class="tableHead">
            <thead>
            <tr>
                <!-- 客户订单号 -->
                <th><p class="width-250px"><spring:message code="slopworkInRequest_show_list_customerContractNo" /></p></th>
                <!-- 颜色-->
                <th><p class="width-120px"><spring:message code="slopworkInRequest_show_list_color" /></p></th>
                <!-- 尺码 -->
                <th><p class="width-120px"><spring:message code="slopworkInRequest_show_list_size" /></p></th>
                <!-- 订单数量 -->
                <th><p class="width-120px"><spring:message code="slopworkInRequest_show_list_indentQuantity" /></p></th>
                <!-- 库存数量 -->
                <th><p class="width-120px"><spring:message code="inventory_requestex_create_details_materialQuantity" /></p></th>
                <!-- 申请入库数量-->
                <th><p class="width-120px"><spring:message code="inventory_request_list_requestQuantity" /></p></th>
            </tr>
            </thead>
        </table>
        <table cellpadding="0" class="tableBody" id="tableRequestDetails">
        <c:if test="${not empty slopworkInRequest.requestDetailsList}">
            <tbody>
            <c:forEach items="${slopworkInRequest.requestDetailsList}" var="requestDetailsInfo" varStatus="status">
            <tr>
                <!-- 客户订单号 -->
                <td><p class="width-250px">${requestDetailsInfo.customerContractNo}</p></td>
                <!-- 颜色-->
                <td><p class="width-120px">${requestDetailsInfo.styleColor}</p></td>
                <!-- 尺码 -->
                <td><p class="width-120px">${fns:getDictName(requestDetailsInfo.styleSize)}</p></td>
                <!-- 订单数量 -->
                <td><p class="width-120px"><fmt:formatNumber value="${requestDetailsInfo.indentQuantity}" pattern="#,##0"/></p></td>
                <!-- 库存数量 -->
                <td><p class="width-120px"><fmt:formatNumber value="${requestDetailsInfo.clothsQuantity}" pattern="#,##0"/></p></td>
                <!-- 申请入库数量-->
                <td><p class="width-120px"><input type="tel" name="requestDetailsList[${status.index}].requestQuantity" value="<fmt:formatNumber value="${requestDetailsInfo.requestQuantity}" pattern="#,##0.###"/>" maxlength="11" onblur="funFormatNumber(this);" onfocus="unFormat(this)"></p></td>
                <input type="hidden" name="requestDetailsList[${status.index}].styleId" value="${requestDetailsInfo.styleId}"/>
                <input type="hidden" name="requestDetailsList[${status.index}].styleSize" value="${requestDetailsInfo.styleSize}"/>
                <input type="hidden" name="requestDetailsList[${status.index}].styleSizeGroup" value="${requestDetailsInfo.styleSizeGroup}"/>
                <input type="hidden" name="requestDetailsList[${status.index}].styleColor" value="${requestDetailsInfo.styleColor}"/>
            </tr>
            </c:forEach>
            </tbody>
        </c:if>    
        </table>
    </div>
</div>
</form>
</body>
</html>